<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>用户登录</title>
    <link rel="stylesheet" href="assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="assets/css/login.css">
</head>
<body>
<div class="login-wrapper">
    <div class="login-header">
        <img src="assets/images/logo.png"> EasyWeb后台开发框架
    </div>
    <div class="login-body">
        <div class="layui-card">
            <div class="layui-card-header">
                <i class="layui-icon layui-icon-engine"></i>&nbsp;&nbsp;用户登录
            </div>
            <form class="layui-card-body layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-username"></i></label>
                    <div class="layui-input-block">
                        <input name="username" type="text" placeholder="账号" class="layui-input"
                               lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-password"></i></label>
                    <div class="layui-input-block">
                        <input name="password" type="password" placeholder="密码" class="layui-input"
                               lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <a href="javascript:;" class="layui-link">帐号注册</a>
                    <a href="javascript:;" class="layui-link pull-right">忘记密码？</a>
                </div>
                <div class="layui-form-item">
                    <button lay-filter="login-submit" class="layui-btn layui-btn-fluid" lay-submit>登 录</button>
                </div>
                <div class="layui-form-item login-other">
                    <label>第三方登录</label>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>
                </div>
            </form>
        </div>
    </div>

    <div class="login-footer">
        <p>© 2019 easyweb.vip 版权所有</p>
        <p>
            <span><a href="https://easyweb.vip" target="_blank">获取授权</a></span>
            <span><a href="https://easyweb.vip/doc/" target="_blank">开发文档</a></span>
            <span><a href="https://demo.easyweb.vip/iframe/" target="_blank">iframe版</a></span>
        </p>
    </div>
</div>

<script type="text/javascript" src="assets/libs/layui/layui.js"></script>
<script>
    layui.config({
        base: 'assets/module/'
    }).use(['layer', 'form', 'config'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var config = layui.config;

        if (config.getToken()) {
            goIndex();
        }
        // 表单提交
        form.on('submit(login-submit)', function (obj) {
            layer.load(2);
            $.post(config.base_server + 'user/login', obj.field, function (res) {
                layer.closeAll('loading');
                if (200 == res.code) {
                    config.putToken(res.access_token);
                    layer.msg(res.msg, {icon: 1, time: 1500}, function () {
                        goIndex();
                    });
                } else {
                    layer.msg(res.msg, {icon: 5});
                }
            }, 'json');
            return false;
        });

        function goIndex() {
            location.replace('/');
        }
    });
</script>
</body>
</html>